package com.dinadi.yidi.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;

import com.dinadi.yidi.ui.MyApplication;


/**
 * Created by Administrator on 2016/3/7.
 */
public class CommonUtil {

    private static SharedPreferences sp;

    /**
     * 获取全局Context
     *
     * @return
     */
    public static Context getContext() {

        return MyApplication.mContext;
    }

    /**
     * 获取当前Apk的版本信息
     */
    public static PackageInfo getVersion() {


        PackageInfo info = null;

        PackageManager manager = getContext().getPackageManager();

        try {

            info = manager.getPackageInfo(getContext().getPackageName(), 0);

        } catch (Exception e) {

            e.printStackTrace();

        }

        return info;
    }

    /**
     * 获取当钱应用的版本名称
     *
     * @return
     */
    public static String getAPKVersonName() throws PackageManager.NameNotFoundException {
        // 获取packagemanager的实例
        PackageManager packageManager = getContext().getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        PackageInfo packInfo = packageManager.getPackageInfo(getContext().getPackageName(), PackageManager.GET_CONFIGURATIONS);
        String version = packInfo.versionName;
        String version2 = packInfo.packageName;
        int version3 = packInfo.versionCode;
        return version;
    }

    /**
     * 检测系统版本是否为6.0
     */
    public static boolean canMakeSmores() {

        return (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1);

    }
}
